package com.highspeed.bdk.gateway.socket.analyze.message.gui.resolver;

import com.highspeed.bdk.gateway.Util;
import com.highspeed.bdk.gateway.socket.analyze.message.gui.base.MessageResolver;

import java.util.HashMap;
import java.util.Map;

/**
 * 3.8 物理链路消息查询的反馈包
 * typedef struct _physicalLink
 * {
 * U32 startId; //链路起点Id 16-bit rionet id + 16-bit portId
 * U32 endId;//链路终点Id  16-bit rionet id + 16-bit portId
 * U32 	U32  bandwidthAvailble; //可用的带宽
 * <p>
 * U8    resvd: 3,
 * linkQuality:
 * startPhyAddr; //起始端口的物理地址
 * U32  endPhyAddr;  //未端口的物理地址
 * 3, // 001 grade 1,010 grade 2, 011 grade 3, 100 grade 4, 101 grade 5
 * backup: 1, //主链路 or 备链路,0 主，1 备
 * linkDown: 1; //down or up ,0 up, 1 down
 * <p>
 * U8 reseved[3];  //一个链路数据的长度用于解释下面的数据
 * } PhysicalLinkFbData;
 */
public class PhysicalLinkResolver extends MessageResolver {


    @Override
    protected Map doResolveBody(byte[] response) {
        Map result = new HashMap();
        Short rionetId = Util.getShort(response, getOffset());
        offset2();
        result.put("startRionetId", rionetId);

        short portId = Util.getShort(response, getOffset());
        offset2();
        logger.info("链路起点rionetId............." + rionetId + ", portId.........." + portId);
        result.put("startPortId", portId);

        rionetId = Util.getShort(response, getOffset());
        offset2();
        result.put("endRionetId", rionetId);

        portId = Util.getShort(response, getOffset());
        offset2();
        logger.info("链路终点rionetId............." + rionetId + ", portId.........." + portId);
        result.put("endPortId", portId);

        int startPhyAddr = Util.getInt(response, getOffset());
        offset4();
        logger.info("startPhyAddr............." + startPhyAddr);
        result.put("startPhyAddr", startPhyAddr);

        int endPhyAddr = Util.getInt(response, getOffset());
        offset4();
        logger.info("endPhyAddr............." + endPhyAddr);
        result.put("endPhyAddr", endPhyAddr);

        int bandwidthAvailble = Util.getInt(response, getOffset());
        offset4();
        logger.info("bandwidthAvailble............." + bandwidthAvailble);
        result.put("bandwidthAvailble", bandwidthAvailble);

        byte u8 = Util.getByte(response, getOffset());
        offset1();
        logger.info("u8............." + u8);
        result.put("u8", u8);

        byte reseved0 = Util.getByte(response, getOffset());
        offset1();
        logger.info("reseved0............." + reseved0);

        byte reseved1 = Util.getByte(response, getOffset());
        offset1();
        logger.info("reseved1............." + reseved1);

        byte reseved2 = Util.getByte(response, getOffset());
        offset1();
        logger.info("reseved2............." + reseved2);
        getContainer().put("phyLink", result);
        return getContainer();
    }

}
